<!DOCTYPE html>
<html class="no-js">
<head>
	<meta charset="utf-8">
	<title>会议室预约</title>
	<meta name="description" content="">
	<meta name="HandheldFriendly" content="True">
	<meta name="MobileOptimized" content="320">
	<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
	<meta http-equiv="cleartype" content="on">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/assets/meeting/css/style.css">
	<link rel="stylesheet" href="/assets/public/layermobile/css/layer.css">
</head>
<body>
<div class="wraper normal" js="wapjs/meeting/js/index.js">
	<div class="head clearfix">
		<a href="{BEESCRM::U('/meeting/meetingAppoint/appointDetails/',array('basic_id' => $basicId,'audited' => 1,'account_id'=>$accountId))}" class="iconfont icon-zuo"></a>
		<span class="head-name">审核通过</span>
	</div>
	<div class="lists">
		<div class="list-line fee">
			是否需要收费<span class="pull-right icon-top"><span class="text-gray" id="yesorno">否</span>
			<span class="isFee iconfont <if condition='$is_fee eq 1'>icon-xuanze1<else />icon-xuanze </if>"></span></span>
			<input type="hidden" name="fee" id="fee" value="{BEESCRM:$is_fee}" />
		</div>

		<div class="list-line">场租费：<input type="text" name="cost" id="cost" value="{BEESCRM:$cost}" placeholder="请输入场租费" <if condition='$is_fee eq 2'>disabled</if>/></div>
	</div>

	<if condition="$hide eq 1">
		<div style="display:none">
			<foreach name="fixed" item="it">
				<a href="javascript:void(0);" class="iconfont icon-shanchu pull-right text-green pop-delete pull-right checker-selected" id="" data-level="{BEESCRM:$k}"
				   data-department_path_id="{BEESCRM:$it['department_path_id']}" data-user_id="{BEESCRM:$it.user_id}"></a>
			</foreach>
		</div>
	</if>


	<neq name="hide" value="1">
		<div class="lists add-list" >
			<div class="list-line check ">
				是否需要多级审核<span class="pull-right icon-top"><span class="text-gray" id="yesorno2"><if condition="$multilevel eq 2">否<else />是</if></span>
				<span class="iconfont <if condition='$multilevel eq 1'>icon-xuanze1<else />icon-xuanze </if>"></span></span>
			</div>

			<if condition="$selectPeople">
				<foreach name="selectDepartment" item="vo" key="k">
					<div class="list-line clearfix" >
						<a class="text pull-left checker choiceChecker" href="javascript:void(0);" data-href="{BEESCRM::U('/meeting/AppointCheck/firstDepartment',array('basic_id' => $basicId,'account_id' => $accountId,'level'=>$k))}">
							<span>选择审核人：
								<foreach name="vo" item="v" key="k1">
									{BEESCRM:$v.department_name}>
								</foreach>
								{BEESCRM:$selectPeople[$k]['real_name']}
							</span>
							<a href="javascript:void(0);" class="iconfont icon-shanchu pull-right text-green pop-delete pull-right checker-selected" id="pop-delete" data-level="{BEESCRM:$k}"
							   data-department_path_id="{BEESCRM:$selectPeople[$k]['department_path_id']}" data-user_id="{BEESCRM:$userId[$k]}"></a>
						</a>
					</div>
				</foreach>
				<div class="list-line">
					<a href="javascript:void(0);" class="text-center text-green <if condition='$count eq $k'>add</if> checker"
					   data-department_path_id="{BEESCRM:$selectPeople[$k]['department_path_id']}" data-user_id="{BEESCRM:$userId[$k]}" data-level="{BEESCRM:$k}" id="add-btn" style="display: block;"><span class="iconfont icon-tianjia"></span> 添加层级</a>
				</div>

				<else />

				<div <if condition="$multilevel eq 2">style="display:none;"</if> >
					<div class="list-line clearfix" >
						<a class="text pull-left checker choiceChecker" data-href="{BEESCRM::U('/meeting/appointCheck/firstDepartment',array('basic_id' => $basicId,'account_id' => $accountId,'level' => 1))}">
							<span>选择审核人：<span class="text-gray">点击选择审核人</span></span>
						</a>
					</div>
					<div class="list-line">
						<a href="#" class="text-green text-center add checker checker-selected" data-department_path_id="" data-user_id="0" style="display: block;"><span class="iconfont icon-tianjia"></span> 添加层级</a>
					</div>
				</div>

			</if>
		</div>
	</neq>

	<div class="btn-box clearfix">
		<a href="{BEESCRM::U('/meeting/meetingAppoint/appointDetails/',array('basic_id' => $basicId,'audited' => 1,'account_id'=>$accountId))}" class="btn half-btn bg-white">取消</a>
		<a href="javascript:void(0)" class="btn half-btn bg-green pass">通过</a>
	</div>
</div>

<input type="hidden" name="basicId" id="basicId" value="{BEESCRM:$basicId}" />
<input type="hidden" name="multilevel" id="multilevel" value="{BEESCRM:$multilevel}" />
<script type="text/javascript" src="/assets/public/seajs/sea.js"></script>
<script enter="publicjs/public" id="confnode" async="async" src="/assets/public/config.js"></script>
<script type="text/javascript" src="/assets/public/jquery-2.1.0.min.js"></script>
<script>

	$(document).on('blur','#cost',function() {
		var reg = new RegExp("^[0-9]*$");
		var cost = $("#cost").val();
		if(!reg.test(cost)) { //不是数字
			$("#cost").val('');
			fm.alert('请输入正确的金额~');return false;
		}
	})

	$('.fee').click(function () {
		if ($(this).find('.iconfont').hasClass('icon-xuanze1')) {
			$(this).find('.iconfont').addClass('icon-xuanze');
			$(this).find('.iconfont').removeClass('icon-xuanze1');
			$(this).find('#yesorno').html('否');
			$("#fee").val(2);     //不需要会务费
			$("#cost").attr('disabled',true);
		} else {
			$(this).find('.iconfont').removeClass('icon-xuanze');
			$(this).find('.iconfont').addClass('icon-xuanze1');
			$(this).find('#yesorno').html('是');
			$("#fee").val(1);  //需要会务费
			$("#cost").attr('disabled',false);
		}
	})



	$(document).on('click',".check",function(){
		if ($(this).find('.iconfont').hasClass('icon-xuanze1')) {
			$(".add-list").html('<div class="list-line check">是否需要多级审核<span class="pull-right"><span class="text-gray" id="yesorno2">否</span> <span class="iconfont icon-xuanze1"></span></span> </div>');
			$('.check').find(' .iconfont').addClass('icon-xuanze');
			$('.check').find(' .iconfont').removeClass('icon-xuanze1');
			$('.check').find('#yesorno2').html('否');
			$("#multilevel").val(2);
			console.log(1);
		} else {
			console.log(2);
			$(this).find(' .iconfont').removeClass('icon-xuanze');
			$(this).find(' .iconfont').addClass('icon-xuanze1');
			$(this).find('#yesorno2').html('是');

			var data = {};

			if($(".isFee").hasClass('icon-xuanze1')) {
				data.is_fee = 1;
			} else{
				data.is_fee = 2;
			}
			data.cost = $("#cost").val();
			data.url = $(this).data('href');
			$("#multilevel").val(1);
			$.ajax({
				url:"/Meeting/MeetingAppoint/saveCost/account_id/{BEESCRM:$accountId}",
				data:data,
				type:'post',
				success:function(result){
					location.href = '/meeting/MeetingAppoint/appointAudited/basic_id/{BEESCRM:$basicId}/account_id/{BEESCRM:$accountId}/multilevel/'+$("#multilevel").val();
				}
			});
			//window.location.href = "{BEESCRM::U('/meeting/meetingAppoint/appointAudited',array('basic_id' => $basicId,'account_id' => $accountId))}"+"/multilevel/1";
		}
	});

	$(document).on('click','.add',function(){
		var flag = 0;
		$(".checker-selected").each(function() {
			if($(this).data('user_id') == 0) {
				flag = 1;
			}
		})
		if(flag == 1) {
			flag = 0;
			fm.alert('请选择审核人员~');
			return false;
		}

		var level = $(this).data('level');
		level = parseInt(level) + 1;

		var url = "{BEESCRM::U('/meeting/appointCheck/firstDepartment',array('basic_id' => $basicId,'account_id' => $accountId))}"+"/level/"+level;
		var html = '<div class="list-line clearfix"><a href="javascript:void(0);" data-href="'+url+'" class="text pull-left choiceChecker">'+' <span>选择审核人：</span>' +
//				'<a href="javascript:void(0);" class="iconfont icon-tianjia pull-right text-green add checker" data-department_path_id="" data-user_id="" data-level="'+level+'"></a>' +
				'<a href="javascript:void(0);" class="iconfont icon-shanchu pull-right text-green pop-delete checker-selected"  data-department_path_id="" data-user_id="" data-level=""></a>' +
				'</a></div>';
		$('#add-btn').before(html);
	});

	$(document).on('click','.pop-delete',function(){ //删除审核人员
		$(this).parent().remove();
		var data = {};
		data.user_id = $(this).data('user_id');
		data.level = $(this).data('level');
		//console.log(data);return;
		if(data.user_id) {
			$.ajax({
				url:"{BEESCRM::U('/meeting/appointCheck/delChecker',array('account_id'=>$accountId))}",
				type:"post",
				data:data,
				dataType:'json',
				success:function(res){
					//res = JSON.parse(res);
					if(res.status == 'S') {
						window.location.href = "{BEESCRM::U('/meeting/meetingAppoint/appointAudited',array('account_id'=>$accountId,'basic_id' => $basicId))}" +'/multilevel/'+$("#multilevel").val();
					}
				},
			})
		}
	});

	$(document).on('click','.pass',function() { //通过
		var data = {};var user_id = [];var department = [];
		data.fee = $("#fee").val();
		data.cost = $("#cost").val();
		if(data.fee == 1 && !data.cost) {
			fm.alert('请输入会议费用~');return false;
		}

		data.multilevel = $("#multilevel").val();
		if(data.multilevel == 1) { //需要多级审核
			$(".checker-selected").each(function() {
				user_id.push($(this).data('user_id'));
				department.push($(this).data('department_path_id'));
			});
			data.department_id = department;
			data.user_id = user_id;
			for(var i=0; i < data.user_id.length; i++) {
				if(user_id[i] == 0 || user_id[i] == '' || user_id[i] == undefined) {
					fm.alert('请选择审核人员~');return false;
				}
			}
		}
		data.basic_id = $("#basicId").val();
		data.type = 1;

		$.ajax({
			url:"{BEESCRM::U('/meeting/MeetingAppoint/appointSetting',array('account_id'=>$accountId))}",
			type:"post",
			data:data,
			dataType:'json',
			success:function(res){
				//res = JSON.parse(res);
				console.log(res);
				if(res.status == 'S') {
					window.location.href = "{BEESCRM::U('/meeting/meetingAppoint/audited',array('account_id'=>$accountId,'audited' => 2))}"
				} else if(res.status == 'F') {
					fm.alert('操作失败~');
				}
			},
		})
	});


	$(document).on('click','.choiceChecker',function() {
		var data = {};

		if($(".isFee").hasClass('icon-xuanze1')) {
			data.is_fee = 1;
		} else{
			data.is_fee = 2;
		}
		data.cost = $("#cost").val();
		data.url = $(this).data('href');

		$.ajax({
			url:"/Meeting/MeetingAppoint/saveCost/account_id/{BEESCRM:$accountId}",
			data:data,
			type:'post',
			success:function(result){
				location.href = data.url;
			}
		});
		//}
	})
</script>

</body>
</html>